3 # Copyright 2006 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
34 my $biblionumber = $query->param('biblionumber');
35 my $review = $query->param('review');
36 my $reviewid = $query->param('reviewid');
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39 template_name => "opac-review.tt",
42 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
46 # FIXME: need to allow user to delete their own comment(s)
48 my ( $clean, @errors, $savedreview );
49 my $biblio = Koha::Biblios->find( $biblionumber );
52 push @errors, { nobiblio => 1 };
53 } elsif( $reviewid ) { # edit existing one, check on creator
54 $savedreview = Koha::Reviews->search({ reviewid => $reviewid, borrowernumber => $borrowernumber })->next;
55 push @errors, { unauthorized => 1 } if !$savedreview;
56 } else { # this check prevents adding multiple comments
57 # FIXME biblionumber, borrowernumber should be a unique key of reviews
58 $savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next;
59 $review = $savedreview? $savedreview->review: $review;
62 if( !@errors && defined $review ) {
63 if ($review !~ /\S/) {
64 push @errors, {empty=>1};
66 $clean = C4::Scrubber->new('comment')->scrub($review);
68 push @errors, {scrubbed_all=>1};
70 if ($clean ne $review) {
71 push @errors, {scrubbed=>$clean};
78 datereviewed => dt_from_string
82 $reviewid = Koha::Review->new(
83 { biblionumber => $biblionumber,
84 borrowernumber => $borrowernumber,
86 datereviewed => dt_from_string
90 unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
94 (@errors ) and $template->param( ERRORS=>\@errors);
96 $review ||= $savedreview->review if $savedreview;
98 'borrowernumber' => $borrowernumber,
100 'reviewid' => $reviewid || 0,
104 output_html_with_http_headers $query, $cookie, $template->output;