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>.
22 use C4::Auth qw( get_template_and_user );
23 use C4::Output qw( output_html_with_http_headers );
27 use Koha::DateUtils qw( dt_from_string );
32 my $biblionumber = $query->param('biblionumber');
33 my $review = $query->param('review');
34 my $reviewid = $query->param('reviewid');
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37 template_name => "opac-review.tt",
40 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
44 # FIXME: need to allow user to delete their own comment(s)
46 my ( $clean, @errors, $savedreview );
47 my $biblio = Koha::Biblios->find( $biblionumber );
50 push @errors, { nobiblio => 1 };
51 } elsif( $reviewid ) { # edit existing one, check on creator
52 $savedreview = Koha::Reviews->search({ reviewid => $reviewid, borrowernumber => $borrowernumber })->next;
53 push @errors, { unauthorized => 1 } if !$savedreview;
54 } else { # this check prevents adding multiple comments
55 # FIXME biblionumber, borrowernumber should be a unique key of reviews
56 $savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next;
57 $review = $savedreview? $savedreview->review: $review;
60 if( !@errors && defined $review ) {
61 if ($review !~ /\S/) {
62 push @errors, {empty=>1};
64 $clean = C4::Scrubber->new('comment')->scrub($review);
66 push @errors, {scrubbed_all=>1};
68 if ($clean ne $review) {
69 push @errors, {scrubbed=>$clean};
76 datereviewed => dt_from_string
80 $reviewid = Koha::Review->new(
81 { biblionumber => $biblionumber,
82 borrowernumber => $borrowernumber,
84 datereviewed => dt_from_string
88 unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
92 (@errors ) and $template->param( ERRORS=>\@errors);
94 $review ||= $savedreview->review if $savedreview;
96 'borrowernumber' => $borrowernumber,
98 'reviewid' => $reviewid || 0,
102 output_html_with_http_headers $query, $cookie, $template->output;