diff options
author | Struan Donald <struan@exo.org.uk> | 2011-06-06 19:33:43 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-06-06 19:33:43 +0100 |
commit | 30cc0004a14ec330ea693a6b6f94e059a4e6abdd (patch) | |
tree | cc2a1beae518db48f6b8c0f72d9a9677fdbe6373 | |
parent | 52347ee7a0b02c12a277fe778b65c26eff2a73a3 (diff) |
edit report admin function
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 264 | ||||
-rw-r--r-- | templates/web/default/admin/list_updates.html | 34 | ||||
-rw-r--r-- | templates/web/default/admin/report_blocks.html | 7 | ||||
-rw-r--r-- | templates/web/default/admin/report_edit.html | 50 | ||||
-rw-r--r-- | templates/web/default/admin/search_reports.html | 43 |
5 files changed, 230 insertions, 168 deletions
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} = + '<p><em>' . _('That problem will now be resent.') . '</em></p>'; + + $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} = + '<p><em>' + . _('I am afraid you cannot confirm unconfirmed reports.') + . '</em></p>'; + $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} = + '<p><em>' . _('Updated!') . '</em></p>'; + + # 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 = '<p><em>' . _('That problem will now be resent.') . '</em></p>'; -# } 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 = '<p><em>' . _('I am afraid you cannot confirm unconfirmed reports.') . '</em></p>'; -# $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 = '<p><em>' . _('Updated!') . '</em></p>'; -# } -# } -# 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} || '<em>' . _('None') . '</em>'; -# (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 = '<li><img align="top" src="' . Cobrand::base_url_for_emails($cobrand, $cobrand_data) . '/photo?id=' . $row{id} . '"> -# <input type="checkbox" id="remove_photo" name="remove_photo" value="1"> -# <label for="remove_photo">' . _("Remove photo (can't be undone!)") . '</label>' 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 = ' <input onclick="return confirm(\'' . _('You really want to resend?') . '\')" type="submit" name="resend" value="' . _('Resend report') . '">' 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 " -# <ul> -# <li><a href='$url'>" . _('View report on site') . "</a> -# <li><label for='title'>" . _('Subject:') . "</label> <input size=60 type='text' id='title' name='title' value='$row_h{title}'> -# <li><label for='detail'>" . _('Details:') . "</label><br><textarea name='detail' id='detail' cols=60 rows=10>$row_h{detail}</textarea> -# <li>" . _('Co-ordinates:') . " $latitude,$longitude (" . _('originally entered') . " $row_h{postcode}, $used_map) -# <li>" . _('For council(s):') . " $council (" . _('other areas:') . " $areas) -# <li>$anon -# <li>$state -# <li>" . _('Category:') . " $row{category} -# <li>" . _('Name:') . " <input type='text' name='name' id='name' value='$row_h{name}'> -# <li>" . _('Email:') . " <input type='text' id='email' name='email' value='$row_h{email}'> -# <li>" . _('Phone:') . " $row_h{phone} -# <li>" . _('Created:') . " $row{created} -# <li>" . _('Confirmed:') . " $confirmed -# <li>" . _('Sent:') . " $whensent $resend -# <li>" . _('Last update:') . " $row{lastupdate} -# <li>" . _('Service:') . " $row{service} -# <li>" . _('Cobrand:') . " $row{cobrand} -# <li>" . _('Cobrand data:') . " $row{cobrand_data} -# <li>" . _('Going to send questionnaire?') . " $questionnaire -# $photo -# </ul> -# "; -# 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; diff --git a/templates/web/default/admin/list_updates.html b/templates/web/default/admin/list_updates.html new file mode 100644 index 000000000..a2936d354 --- /dev/null +++ b/templates/web/default/admin/list_updates.html @@ -0,0 +1,34 @@ +<h2>Updates</h2> + +<table cellspacing="0" cellpadding="2" border="1"> + <tr> + <th>[% loc('ID') %]</th> + <th>[% loc('State') %]</th> + <th>[% loc('Name') %]</th> + <th>[% loc('Email') %]</th> + <th>[% loc('Created') %]</th> + <th>[% loc('Anonymous') %]</th> + <th>[% loc('Cobrand') %]</th> + <th>[% loc('Text') %]</th> + <th>[% loc('*') %]</th> + </tr> +[% FOREACH update IN updates -%] + <tr[% ' class="hidden"' IF update.state == 'hidden' || ( problem.state && problem.state == 'hidden' ) %]> + <td>[%- IF update.state == 'confirmed' -%] + [%- cobrand_data = update.cobrand_data %] + [%- cobrand_data = c.data_for_generic_update IF !update.cobrand %] + <a href="[% c.uri_for_email( '/report', update.problem.id, cobrand_data ) %]#update_[% update.id %]">[% update.id %]</a> + [%- ELSE %] + [%- update.id %] + [%- END -%]</td> + <td>[% update.state %]</td> + <td>[% update.name | html %]</td> + <td>[% update.user.email | html %]</td> + <td>[% PROCESS format_time time=update.created %]</td> + <td>[% IF update.anonymous %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</td> + <td>[% update.cobrand %]<br>[% update.cobrand_data | html %]</td> + <td>[% update.text | html %]</td> + <td><a href="[% c.uri_for( 'update_edit', update.id ) %]">Edit</a></td> + <tr> +[% END -%] +</table> diff --git a/templates/web/default/admin/report_blocks.html b/templates/web/default/admin/report_blocks.html new file mode 100644 index 000000000..1fe650f15 --- /dev/null +++ b/templates/web/default/admin/report_blocks.html @@ -0,0 +1,7 @@ +[% BLOCK value_or_nbsp -%] + [%- IF value %][% value | html %][% ELSE %] [% END %] +[%- END %] + +[% BLOCK format_time -%] + [%- IF time %][% time.ymd %] [% time.hms %][% ELSE %][% no_time || ' ' %][% END %][% no_time = '' %] +[%- END %] diff --git a/templates/web/default/admin/report_edit.html b/templates/web/default/admin/report_edit.html new file mode 100644 index 000000000..1a03da7e1 --- /dev/null +++ b/templates/web/default/admin/report_edit.html @@ -0,0 +1,50 @@ +[% INCLUDE 'admin/header.html' title=tprintf(loc('Editing problem %d'), problem.id ) -%] +[% PROCESS 'admin/report_blocks.html' %] + +[% status_message %] + +<form method="post" action="[% c.uri_for( 'report_edit', problem.id ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> + <input type="hidden" name="token" value="[% token %]" > + <input type="hidden" name="submit" value="1" > +<ul> + [%- cobrand_data = problem.cobrand_data %] + [%- cobrand_data = c.data_for_generic_problem IF !problem.cobrand %] +<li><a href="[% c.uri_for_email( '/report', problem.id, cobrand_data ) %]">[% loc('View report on site' )%]</a></li> +<li><label for='title'>[% loc('Subject:') %]</label> <input size=60 type='text' id='title' name='title' value='[% problem.title | html %]'></li> +<li><label for='detail'>[% loc('Details:') %]</label><br><textarea name='detail' id='detail' cols=60 rows=10>[% problem.detail | html %]</textarea></li> +<li>[% loc('Co-ordinates:') %] [% problem.latitude %], [% problem.longitude %] ( [% loc('originally entered') %] [% problem.postcode | html %] , [% IF problem.used_map %][% loc('used map') %][% ELSE %][% loc("didn't use map") %][% END %])</li> +<li>[% loc('For council(s):') %] [% IF problem.council %][% problem.council %][% ELSE %]<em>[% loc('None' ) %]</em>[% END %] ([% loc('other areas:') %] [% problem.areas | remove('^,') | remove( ',$' ) %])</li> +<li><label for="anonymous">[% loc('Anonymous:') %]</label> <select name="anonymous" id="anonymous"> +<option [% 'selected ' IF problem.anonymous %]value="1">Yes</option> +<option [% 'selected ' IF !problem.anonymous %]value="0">No</option> +</select></li> +<li><label for="state">[% loc('State:') %]</label> <select name="state" id="state"> + [% FOREACH state IN [ ['confirmed', loc('Open')], ['fixed', loc('Fixed')], ['hidden', loc('Hidden')], ['partial', loc('Partial')],['unconfirmed',loc('Unconfirmed')] ] %] + <option [% 'selected ' IF state.0 == problem.state %] value="[% state.0 %]">[% state.1 %]</option> + [% END %] +</select></li> +<li>[% loc('Category:') %] [% problem.category | html %] </li> +<li>[% loc('Name:') %] <input type='text' name='name' id='name' value='[% problem.name | html %]'></li> +<li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% problem.user.email | html %]'></li> +<li>[% loc('Phone:') %] [% problem.user.phone | html %]</li> +<li>[% loc('Created:') %] [% PROCESS format_time time=problem.created %]</li> +<li>[% loc('Confirmed:') %] [% PROCESS format_time time=problem.confirmed no_time='-' %]</li> +<li>[% loc('Sent:') %] [% PROCESS format_time time=problem.whensent %] [% IF problem.state == 'confirmed' %]<input onclick="return confirm('[% loc('You really want to resend?') %]')" type="submit" name="resend" value="[% loc('Resend report') %]">[% END %]</li> +<li>[% loc('Last update:') %] [% PROCESS format_time time=problem.lastupdate %]</li> +<li>[% loc('Service:') %] [% problem.service %]</li> +<li>[% loc('Cobrand:') %] [% problem.cobrand %]</li> +<li>[% loc('Cobrand data:') %] [% problem.cobrand_data %]</li> +<li>[% loc('Going to send questionnaire?') %] [% IF problem.send_questionnaire %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</li> + +[% IF problem.photo %] +[% photo = problem.get_photo_params %] +<li><img alt="" height="[% photo.height %]" width="[% photo.width %]" src="[% photo.url %]"> +<input type="checkbox" id="remove_photo" name="remove_photo" value="1"> +<label for="remove_photo">[% loc("Remove photo (can't be undone!)") %]</label></li> +[% END %] +</ul> +<input type="submit" name="Submit changes" value="[% loc('Submit changes') %]" ></form> + +[% INCLUDE 'admin/list_updates.html' %] + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/default/admin/search_reports.html b/templates/web/default/admin/search_reports.html index e2769e5ca..3c8b21a71 100644 --- a/templates/web/default/admin/search_reports.html +++ b/templates/web/default/admin/search_reports.html @@ -1,12 +1,5 @@ [% INCLUDE 'admin/header.html' title=loc('Search Reports') %] - -[% BLOCK value_or_nbsp -%] - [%- IF value %][% value | html %][% ELSE %] [% END %] -[%- END %] - -[% BLOCK format_time -%] - [%- IF time %][% time.ymd %] [% time.hms %][% ELSE %] [% END %] -[%- END %] +[% PROCESS 'admin/report_blocks.html' %] <form method="get" action="[% c.uri_for('search_reports') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> <label for="search">Search:</label> <input type="text" name="search" size="30" id="search"> @@ -61,40 +54,8 @@ [%- END -%] </table> -<h2>Updates</h2> +[% INCLUDE 'admin/list_updates.html' %] -<table cellspacing="0" cellpadding="2" border="1"> - <tr> - <th>[% loc('ID') %]</th> - <th>[% loc('State') %]</th> - <th>[% loc('Name') %]</th> - <th>[% loc('Email') %]</th> - <th>[% loc('Created') %]</th> - <th>[% loc('Anonymous') %]</th> - <th>[% loc('Cobrand') %]</th> - <th>[% loc('Text') %]</th> - <th>[% loc('*') %]</th> - </tr> -[% FOREACH update IN updates -%] - <tr[% ' class="hidden"' IF update.state == 'hidden' || ( problem.state && problem.state == 'hidden' ) %]> - <td>[%- IF update.state == 'confirmed' -%] - [%- cobrand_data = update.cobrand_data %] - [%- cobrand_data = c.data_for_generic_update IF !update.cobrand %] - <a href="[% c.uri_for_email( '/report', update.problem.id, cobrand_data ) %]#update_[% update.id %]">[% update.id %]</a> - [%- ELSE %] - [%- update.id %] - [%- END -%]</td> - <td>[% update.state %]</td> - <td>[% update.name | html %]</td> - <td>[% update.user.email | html %]</td> - <td>[% PROCESS format_time time=update.created %]</td> - <td>[% IF update.anonymous %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</td> - <td>[% update.cobrand %]<br>[% update.cobrand_data | html %]</td> - <td>[% update.text | html %]</td> - <td><a href="[% c.uri_for( 'update_edit', update.id ) %]">Edit</a></td> - <tr> -[% END -%] -</table> [% END %] [% INCLUDE 'admin/footer.html' %] |