X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=opac%2Fopac-review.pl;h=f8e86bac13e037b355ac0a1531e91c34b6dd2e46;hb=177542bf5208e5e053ac9b1500d2536e1eff5ae2;hp=16ed56af963da53c24df39513452b2c517d61f21;hpb=aef1dd15fbe37a8a9c30ba4b38f7ecd6c1fea54d;p=koha.git diff --git a/opac/opac-review.pl b/opac/opac-review.pl index 16ed56af96..f8e86bac13 100755 --- a/opac/opac-review.pl +++ b/opac/opac-review.pl @@ -4,36 +4,38 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -use strict; -use warnings; -use CGI; +use Modern::Perl; +use CGI qw ( -utf8 ); use C4::Auth; use C4::Koha; use C4::Output; -use C4::Review; use C4::Biblio; use C4::Scrubber; use C4::Debug; +use Koha::DateUtils; +use Koha::Review; +use Koha::Reviews; my $query = new CGI; my $biblionumber = $query->param('biblionumber'); my $review = $query->param('review'); +my $reviewid = $query->param('reviewid'); my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { - template_name => "opac-review.tmpl", + template_name => "opac-review.tt", query => $query, type => "opac", authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), @@ -42,10 +44,21 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( # FIXME: need to allow user to delete their own comment(s) +my ( $clean, @errors, $savedreview ); my $biblio = GetBiblioData($biblionumber); -my $savedreview = getreview($biblionumber,$borrowernumber); -my ($clean, @errors); -if (defined $review) { + +if( !$biblio ) { + push @errors, { nobiblio => 1 }; +} elsif( $reviewid ) { # edit existing one, check on creator + $savedreview = Koha::Reviews->search({ reviewid => $reviewid, borrowernumber => $borrowernumber })->next; + push @errors, { unauthorized => 1 } if !$savedreview; +} else { # this check prevents adding multiple comments + # FIXME biblionumber, borrowernumber should be a unique key of reviews + $savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next; + $review = $savedreview? $savedreview->review: $review; +} + +if( !@errors && defined $review ) { if ($review !~ /\S/) { push @errors, {empty=>1}; } else { @@ -59,24 +72,36 @@ if (defined $review) { my $js_ok_review = $clean; $js_ok_review =~ s/"/"/g; # probably redundant w/ TMPL ESCAPE=JS $template->param(clean_review=>$js_ok_review); - if ($savedreview) { - updatereview($biblionumber, $borrowernumber, $clean); - } else { - savereview($biblionumber, $borrowernumber, $clean); - } + if ($savedreview) { + $savedreview->set( + { + review => $clean, + approved => 0, + datereviewed => dt_from_string + } + )->store; + } else { + $reviewid = Koha::Review->new( + { biblionumber => $biblionumber, + borrowernumber => $borrowernumber, + review => $clean, + } + )->store->reviewid; + } unless (@errors){ $template->param(WINDOW_CLOSE=>1); } } } } (@errors ) and $template->param( ERRORS=>\@errors); ($cgi_debug) and $template->param(cgi_debug=>1 ); +$review = $clean; +$review ||= $savedreview->review if $savedreview; $template->param( 'biblionumber' => $biblionumber, 'borrowernumber' => $borrowernumber, - 'review' => $clean || $savedreview->{'review'}, - 'reviewid' => $query->param('reviewid') || 0, + 'review' => $review, + 'reviewid' => $reviewid || 0, 'title' => $biblio->{'title'}, ); output_html_with_http_headers $query, $cookie, $template->output; -